package com.fr.report;

import com.fr.report.cellElement.Formula;
import com.fr.report.core.ReportHelper;
import com.fr.report.core.ScriptUtils;
import com.fr.report.core.SupportAddCellCaseContainer;
import com.fr.report.script.Calculator;
import com.fr.report.script.ParameterMapNameSpace;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;

public class RWorkSheet extends AbstractReport
  implements ResultReport
{
  public ResultWorkBook getResultWorkBook()
  {
    return ((ResultWorkBook)super.getBook());
  }

  public void setResultWorkBook(ResultWorkBook paramResultWorkBook)
  {
    super.setBook(paramResultWorkBook);
  }

  public RWorkSheet cloneWithoutCell()
    throws CloneNotSupportedException
  {
    RWorkSheet localRWorkSheet = (RWorkSheet)super.cloneWithoutCellCase();
    return localRWorkSheet;
  }

  protected CellElement createDefaultCellElementCase()
  {
    return new DefaultCellElement();
  }

  public void recalculate(Map paramMap)
  {
    ReportHelper.clearFormulaResult(this);
    Calculator localCalculator = Calculator.createCalculator();
    localCalculator.pushNameSpace(ParameterMapNameSpace.create(paramMap));
    localCalculator.setAttribute(ScriptUtils.REC_CE_LIST, new LinkedList());
    Iterator localIterator = cellIterator();
    while (true)
    {
      CellElement localCellElement;
      Formula localFormula;
      while (true)
      {
        Object localObject;
        do
        {
          if (!(localIterator.hasNext()))
            return;
          localCellElement = (CellElement)localIterator.next();
          localObject = localCellElement.getValue();
        }
        while (!(localObject instanceof Formula));
        localFormula = (Formula)localObject;
        if (localFormula.getResult() == null)
          break;
      }
      ScriptUtils.executeCellElementFormula(localCalculator, localFormula, this, getBook(), localCellElement);
    }
  }

  public void addCellElement(CellElement paramCellElement, boolean paramBoolean)
  {
    if (!(paramBoolean))
      try
      {
        super.addCellElement(paramCellElement, paramBoolean);
      }
      catch (UnsupportedOperationException localUnsupportedOperationException)
      {
        setCellCase(SupportAddCellCaseContainer.pack(getCellCase()));
        super.addCellElement(paramCellElement, paramBoolean);
      }
    else
      super.addCellElement(paramCellElement, paramBoolean);
  }
}